﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CS_BEGINNER_TO_PROFICIENT.STD.DelegatedSTD
{
    public delegate void MyEventHander(string message);

    public class Publisher
    {
        public event MyEventHander MyEvent;

        public void RaiseEvent(string message)
        {
            MyEvent?.Invoke(message);
        }
    }

    public class Subscriber
    {
        public void OnEventRaised(string message)
        {
            Console.WriteLine("Event recevied: " + message);
        }
    }

    public class DelegatedSTDP4
    {
        public static void Execute()
        {
            Publisher publisher = new Publisher();
            Subscriber subscriber = new Subscriber();

            publisher.MyEvent += subscriber.OnEventRaised;
            publisher.RaiseEvent("Hello World");
        }
    }
}
